package learning.spring.helloworld;

import learning.spring.helloworld.custom.CustomEventPublisher;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan
public class Application {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(Application.class);
        // Hello hello = applicationContext.getBean("hello", Hello.class);
        // System.out.println(hello.hello());

        // 获取自定义事件发布者bean
        applicationContext.getBean("customEventPublisher", CustomEventPublisher.class)
                .fireCustomEvent();// 发布事件

        applicationContext.close();// 进入源码后能看到close方法中，会发布 ContextClosedEvent 关闭事件
    }
}
